# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=youtube-dl
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2021.01.24.1
pkgrel=1
pkgdesc="A command-line program to download videos from YouTube.com and a few more sites (mingw-w64)"
arch=('any')
url="https://youtube-dl.org"
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-setuptools")
optdepends=("${MINGW_PACKAGE_PREFIX}-ffmpeg: for video post-processing")
            #'rtmpdump: for rtmp streams support'
            #'atomicparsley: for embedding thumbnails into m4a files'
            #'python-pycryptodome: for hlsnative downloader'
source=("https://github.com/ytdl-org/${_realname}/releases/download/${pkgver}/${_realname}-${pkgver}.tar.gz"{,.sig})
sha256sums=('de2516d3e6de73f2089dd0ccb0880364c7da34e5c902631feb96d4ebc6d13000'
            'SKIP')
validpgpkeys=('ED7F5BF46B3BBED81C87368E2C393E0F18A9236D') # Sergey M. <dstftw@gmail.com>

build() {
  cd "${srcdir}/${_realname}"
  ${MINGW_PREFIX}/bin/python setup.py --quiet build
}

package() {
  cd "${srcdir}/${_realname}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=;--install-purelib=;--install-data=" \
    ${MINGW_PREFIX}/bin/python setup.py --quiet install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1

  PREFIX_WIN=$(cygpath -m ${MINGW_PREFIX})
  sed -s "s|${PREFIX_WIN}/bin/||g" \
    -i "${pkgdir}${MINGW_PREFIX}/bin/youtube-dl-script.py"

  install -D -m644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
